﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Eureka.modelos;

namespace Eureka
{
    public partial class adminLogon : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void cmdLogin_Click(object sender, EventArgs e)
        {
            if (validarUsuario(txtUserName.Value, txtUserPass.Value))
            {
                Administrador adm = Administrador.buscar(txtUserName.Value);
                Session["id"] = adm.Id;


                // inserir flag de logado no banco
                Administrador admin = new Administrador((int)Session["id"]);
                admin.logar();

                // inserindo no log
                Log log = new Log((int)Session["id"], "Login", 0);
                log.criar();

                FormsAuthentication.RedirectFromLoginPage(adm.Login, false);

            }
            else
            {
                lblMsg.Text = "Login inválido!";
                lblMsg.Visible = true;
            }
        }

        private bool validarUsuario(String usrnm, String pswd) {
            return Administrador.autenticar(usrnm,pswd);
        }

    }
}
